Make sure weather templates work with both Metric and Imperial unit systems#48641
Make sure weather templates work with both Metric and Imperial unit systems#48641csoltenborn wants to merge 5 commits intohome-assistant:devfrom
Conversation
|
Hey there @PhracturedBlue, @tetienne, mind taking a look at this pull request as its been labeled with an integration ( |
|
This means that as a user with Imperial units in nearly all my current entities, I now need to convert them to be in Metric units to use this template? Then the template entities will convert them back? I don't see the benefit here. I think it would be easier and more straightforward to document the units expected in the documentation. |
Have you read this comment? As far as I can see, there is no other way if users shall be able to create weather templates which work with Metric as well as Imperial unit system. Note that I'm relatively new to HA - I stand ready to be corrected... As a side note: I don't care whether templates shall return Metric or Imperial values (as long as the unit is fixed). |
|
I agree that users cannot make a template that can convert back and forth from Metric and Imperial, but I don't think this will be a very common use. Users stay in one unit system I would think, and only need to set up units once in this template. Another issue is that this PR only converts the current windspeed, for example, but not windspeed in the forecasts. So in Imperial units, the windspeed would have to be supplied in two different units. |
|
I agree that this is not a common use case, but this solution has another advantage: It is more transparent. I had to figure out what units to return on my own, and had to understand that I just had to compute the values as they fit and ignore the problem with different time systems (I found that confusing). I also want to point you to the fact that Concerning the forecast issue: The main use case here is that the forecast is reused by another weather entity (as I did in my example configuration above: |
This could be satisfied by putting the required units of both systems into the user documentation. Just my opinion, and you should wait for other opinions. |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
The bot and I are still waiting for other opinions... |
|
I found this pr by luck after trying to make the ecobee integration compatible with both metric & imperial, and have a few thoughts:
I'm not a maintainer here so this is not authoritative advice at all. Just hope it helps 😁 |
That's probably true, but I still don't see any alternative since I don't see a way to convert units in a weather template (because it's just not possible to know what the correct unit would be).
There might be a few more (I remember some weather integrations showing the correct units quite some time after changing the unit system through the UI), but I agree that this is dealt with in an inconsistent manner in many places (and that's clearly a sign for lack of documentation etc).
This might indeed be an option. An even simpler (and for my feeling more clear) approach would be to have HA internally work with fixed units (e.g., °C for temperature), and only make the conversion to the localized unit at the UI level. However, that also comes with drawbacks (e.g., what units do I rely on in my automations? Also going for the internal unit (°C) would make it more difficult to write automations, and relying on the localized unit would break automations if the unit system is changed). Thus, I think that the latter (providing explicit units) might indeed be the best option. In fact, again I think that the existence of |
Agree. Making the additional |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
@csoltenborn are you still working on this? If you don't have the time, I'd be interested in picking up the work. |
|
Well, I'm kind of waiting for more feedback - not sure what could be done at the moment. What do you have in mind? |
|
@frenck Maybe this PR is also stalled because of wrong codeowner. |
I'd love to hear some too 😁
Perhaps this is better to leave until a maintainer gives feedback, but it would be nice to allow the author to specify which units they are using in the template. I'd also like to adapt the code in the PR to weather integrations. Is this something you would like to work on, or I could make my own PR (double the exposure!) |
|
It seems that the bot tagged the wrong people. That may explain why this PR has less exposure than you expect. AFAIU from commits and comments @emontnemery is the code owner of the template integration. |
|
@FrnchFrgg Thanks for pointing this out - in fact, I thought about closing this PR after the 2nd bot complaint because I felt kind of ignored :-) @rianadon From the discussions, it appeared to me that "unit issues" are deeply integrated into HA, and that there is no simple way to fix this (since a "real" fix would break lots of integrations). What do you have in mind with "adapt PR to weather integrations"? |
|
@csoltenborn Instead of forcing the output of the templates to be one or the other, and then converting back, we could make the expected unit available as a template variable, so we would pass DocumentationThe existing documentation is vague to say the least and needs to be updated to make that clear. Sensor unitsAssuming that the input to the templates are sensor states, they should be automatically converted to the unit system configured by the user. There's a (currently stalled) effort underway to move unit conversion to the sensor base class so it doesn't have to be implemented in every sensor: #48261. |
|
This looks awesome @emontnemery! Your PR is exactly what I was hoping for. |
|
Hey, there's some feedback! :-) Thanks, @emontnemery ! @rianadon I'm not going to have time for this in the coming weeks - would you indeed like to pick up my work? |
|
I'll see what I can do! |
|
Can do! My plan as of now is:
Alternatively, I could keep my changes smaller by only implementing # 3, then doing unit conversion in @emontnemery unfortunately Things I'm not sure on:
|
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
@rianadon, @csoltenborn do you plan to pick this up? |
|
Hey. Sorry I've gottten busy lately. I was waiting for #53846 to get merged, and I haven't had the chance yet to make the revisions you requested to that PR. I do plan on picking this up but it'll likely be several weeks until I get to it. |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
Breaking change
The values of weather templates now have to be provided in fixed units as documented here. This is to make sure that weather templates work with both Metric and Imperial unit systems. To fix your weather template, make sure that you convert the template values to the appropriate units within your template code.
Proposed change
Weather templates currently can not be created such that they support both Metric and Imperial unit systems (see this comment for details). This PR fixes that problem by requiring certain units for the template values, and by converting them to the appropriate units in the
WeatherTemplateclass, where information on the configured unit system is available.Type of change
Example entry for
configuration.yaml:Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: